﻿
@{
    Layout = null;
}

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>登录</title>
    <link href="~/lib/layui2.5.6/css/layui.css" rel="stylesheet" />
    <link href="/css/login.css" rel="stylesheet" />
</head>
<body>
    <div class="top">OLFrame&nbsp;-&nbsp;简单基础后台(.netcore)</div>
    <div class="content">
        <div class="login">
            <div class="title">后台登录</div>
            <div class="line">
                <img class="smallImg" src="/images/login/icon1.png" />
                <input placeholder="请输入账号" type="text" id="username" name="username" value="admin" />
            </div>
            <div class="line">
                <img class="smallImg" src="/images/login/icon2.png" />
                <input placeholder="请输入密码" type="password" name="password" id="password" value="123456" />
            </div>
            <button type="button" class="logBut" onclick="login()">登&nbsp;&nbsp;录</button>
        </div>
    </div>
    <script src="/lib/jquery/dist/jquery.js"></script>
    <script src="~/lib/layui2.5.6/layui.js"></script>
    <script src="~/js/jsencrypt.js"></script>
    <script>
        layui.use(['layer'], function () {

        });
        function login() {
            var userName = $("#username").val();
            var password = $("#password").val();

            //获取公钥
            var publicKey = "";
            $.ajax({
                url: "/Common/GetRSAPublicKey",
                async: false,
                success: function (data) {
                    publicKey = data;
                }
            });

            //rsa加密随机密钥
            var rsa = new JSEncrypt();
            //设置后端接口传回的公钥（无需对公钥字符串做任何处理）
            rsa.setPublicKey(publicKey);
            //注意：RSA加解密有大小限制（最多117 bytes）
            password = rsa.encrypt(password);

            //开启loading
            layer = layui.layer;
            var indexLoad = layer.load(3, { shade: 0.1, zIndex: 19891017 });

            $.ajax({
                url: "/Home/PostLogin",
                type: "post",
                data: { userName: userName, password: password },
                success: function (data) {
                    if (data.state == 1) {
                        window.location.href = "/home/main";
                    }else if (data.state == 0) {
                        layer.close(indexLoad);
                        layer.msg(data.msg, { shade: 0.1, icon: 5 });
                    }
                    else {
                        layer.close(indexLoad);
                        parent.layer.open({
                            title: '提示'
                            , content: data.msg
                            , shade: 0.1
                            , icon: 2
                        });
                    }
                }
            });
        }
    </script>
</body>
</html>
